package com.gc.web.controller.api;

import com.gc.common.constant.Constants;
import com.gc.common.utils.StringUtils;
import com.gc.framework.web.base.ApiBaseController;
import com.gc.system.domain.SysDictData;
import com.gc.system.service.ISysDictDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;


/**
 * @author liujinteng
 * @title 系统字典api接口
 * @date 2020-11-18
 */
@CrossOrigin
@Controller
@RequestMapping("/api/sysDictionary")
public class ApiSysDictionaryController extends ApiBaseController {

    @Autowired
    ISysDictDataService sysDictDataService;

    /**
     * 根据code查询需要的数据字典接口
     *
     * @param code
     * @return
     */
    @GetMapping("/searchDictionList")
    @ResponseBody
    public Map<String, Object> seachDictionList(String code) {

        if (StringUtils.isEmpty(code)) {
            return error(Constants.UNVERIFY, "缺少必填参数:code");
        }
        List<SysDictData> dataList = sysDictDataService.selectDictDataByType(code);
        return success(dataList);
    }
}
